package Retorfit对象;

import java.util.List;

import Bean.ArticleBean;
import Two_interface.GetArticleListInfoService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by pc on 2017/5/24.
 */

public  abstract class ArticleModel {
    private static final String BASE_URL = "http://amicool.neusoft.edu.cn/";
    Retrofit retrofit;

   public ArticleModel(){
   retrofit =new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .baseUrl(BASE_URL)
            .build();
}

    public void MakeAAsk(String mod,int page,String sessionID){
        GetArticleListInfoService getArticleListInfoService = retrofit.create(GetArticleListInfoService.class);
        Call<List<ArticleBean>> call=getArticleListInfoService.getResult(mod,page,sessionID);
        Ask_A_ask(call);
}

     public void  Ask_A_ask(Call<List<ArticleBean>> call){
         call.enqueue(new Callback<List<ArticleBean>>() {
             @Override
             public void onResponse(Call<List<ArticleBean>> call, Response<List<ArticleBean>> response) {
                 if (response.isSuccessful() && response.body() != null)
                 ArticleonResponse(call,response);
             }

             @Override
             public void onFailure(Call<List<ArticleBean>> call, Throwable t) {
                 ArticleonFailure(call,t);
             }
         });
     }
    public abstract void ArticleonResponse(Call<List<ArticleBean>> call, Response<List<ArticleBean>> response);
    public abstract void ArticleonFailure(Call<List<ArticleBean>> call, Throwable t);
}
